package com.hui.stock.controller;

import com.hui.stock.pojo.domain.MenuDomain;
import com.hui.stock.service.RoleService;
import com.hui.stock.vo.req.RolePageInfoReqVo;
import com.hui.stock.vo.req.AddRoleReqVo;
import com.hui.stock.vo.req.UpdateRoleReqVo;
import com.hui.stock.vo.resp.PageResult;
import com.hui.stock.vo.resp.R;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: ymh
 * @date: 2024/12/30 16:01
 * @description:
 */
@ApiOperation("角色相关接口")
@RestController
@RequestMapping("/api")
public class RoleController {

    @Autowired
    private RoleService roleService;
    /**
     * 分页查询当前角色信息
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "1",example = "1"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "10",example = "10")
    })
    @ApiOperation(value = "分页查询当前角色信息", httpMethod = "POST")
    @PostMapping("/roles")
    public R<PageResult> getRolePageInfo(@RequestBody RolePageInfoReqVo rolePageInfoReqVo){
        return roleService.getRolePageInfo(rolePageInfoReqVo);
    }

    @ApiOperation("树状结构回显权限集合,底层通过递归获取权限数据集合")
    @GetMapping("/permissions/tree/all")
    public R<List<MenuDomain>> getAllPermissionsTree(){
        return roleService.getAllPermissionsTree();
    }

    @ApiOperation("添加角色和角色关联权限")
    @PostMapping("/role")
    public R addRole(@RequestBody AddRoleReqVo roleReqVo) {
        return roleService.addRole(roleReqVo);
    }

    @ApiOperation("添加角色和角色关联权限")
    @PutMapping ("/role")
    public R updateRole(@RequestBody UpdateRoleReqVo updateRoleReqVo) {
        return roleService.updateRole(updateRoleReqVo);
    }


    @ApiOperation("查询角色关联权限")
    @GetMapping("/role/{roleId}")
    public R<List<Long>> getRolePermissions(@PathVariable Long roleId){
        return roleService.getRolePermissions(roleId);
    }

    @ApiOperation("删除角色和角色关联权限")
    @DeleteMapping ("/role/{roleId}")
    public R<List<Long>> deleteRoleAndPermissions(@PathVariable Long roleId){
        return roleService.deleteRoleAndPermissions(roleId);
    }
    @ApiOperation("更新用户的状态信息")
    @PostMapping("/role/{roleId}/{status}")
    public R updateRoleStatus(@PathVariable Long roleId, @PathVariable Integer status){
        return roleService.updateRoleStatus(roleId,status);
    }

}
